import TableLyout from '@/components/commonPublic/tableLyout.vue'
import actions from "@/actions";
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
import API from '@/utils/commonRequest.js'
import formJs from "./regexDetail.js"; //新增弹框配置

export default {
    name: "wayedit",
    data() {
        return {
            name: "wayedit",
            userNature: null, //用户Nature
            searchObj: formJs.searchObj, //搜索条件
            // 列表
            getList: {
                fprojectid: "",
                fCompanyid: "", // 施工标段id
            },
            url: null,
        };
    },
    components: {
        TableLyout,
        publicForm,
    },
    mounted() {
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
        }, true);

        API.userNature().then((res) => {
            if (res.errcode == 0) {
                this.userNature = res.data.Nature
            }
        }).catch((err) => {
            console.log(err)
        })
        this.getDate()
    },
    methods: {
        // 获取数据
        yj_searchForm(data) {
            console.log("获取列表数据", data);
            window.sessionStorage.setItem("GxpavingRolling-getList", JSON.stringify(data));
            var id;
            if (data.fCompanyid != "") {
                id = data.fCompanyid;
            } else {
                id = data.fprojectid;
            }
            this.url = "http://39.99.220.82:88/wayedit?token=fTI4MzQ2NTIxNzE6InJ6dmciLHl5aGE6InplcmciLDc5OiJxdiIsIjg2OXIzcG9zIjoicXZhIiwiS1RXTSI6ImVyZmgie0JDUV9HVlpaSEY=&sectionId=" + id + "&roadType=2";
        },

        getDate() {
            if (JSON.parse(sessionStorage.getItem("GxpavingRolling-getList"))) {
                var data = JSON.parse(sessionStorage.getItem("GxpavingRolling-getList"));
                if (data.fprojectid != "") {
                    this.getTender(data.fprojectid);
                } else {
                    data.fprojectid = this.projectsObj[1].fItemValue;
                    this.getTender(data.fprojectid);
                }
                this.getList = {
                    fprojectid: data.fprojectid,
                    fCompanyid: data.fCompanyid, //左侧选中组织机构id

                };
            }
        },
        // 调标段
        async getTender(e) {
            await this.$http(
                "https://xayj.limsapp.cn:8500/IOTManagement/Base/Company/getGXBaseCompanyList.do?projectId=" +
                e, {
                headers: {
                    "Content-Type": "application/json",
                    Authorization: localStorage.getItem("access_token"),
                },
            }
            ).then((res) => {
                if (res.status == 200) {
                    var data = res.data.data.GXCompanyList;
                    this.tendersObj = [];
                    if (data.length == 0) {
                        this.$message.warning({
                            content: "有其他人员登录此账号！",
                            duration: 1000,
                        });
                        setTimeout(() => {
                            window.location.href = "https://yggc.cncico.com:1080/login";
                        }, 1200);
                    } else    if (data.length == 1) {
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                        this.getList.fCompanyid = data[0].sectionId;
                    } else {
                        this.tendersObj = [{
                            fItemName: "所有标段",
                            fItemValue: "",
                        },];
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                    }
                }
            });
        },

    },
};